import Vue from "vue";
import App from "./App.vue";
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import router from "./router";
import store from "./store";
import md5 from 'js-md5';
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import './assets/icon/iconfont.css'
import VCharts from 'v-charts'
Vue.prototype.$md5 = md5;
Vue.use(VCharts)
Vue.use(mavonEditor)

//这样配置后相当于配置插件，这样全局就可以通过this.+方法调用
import {postKeyValueRequest} from "./utils/api";
import {getRequest} from "./utils/api";
import {postRequest} from "./utils/api";
import {putRequest} from "./utils/api";
import {deleteRequest} from "./utils/api";
import  "./utils/date"
Vue.prototype.postKeyValueRequest = postKeyValueRequest;//注意这不是方法的表示，所以不需要加括号
Vue.prototype.getRequest = getRequest;
Vue.prototype.postRequest = postRequest;
Vue.prototype.putRequest = putRequest;
Vue.prototype.deleteRequest = deleteRequest;

//进度条
NProgress.inc(0.2);
NProgress.configure({
  easing: 'ease',  // 动画方式
  speed: 500,  // 递增进度条的速度
  showSpinner: false, // 是否显示加载ico
  trickleSpeed: 200, // 自动递增间隔
  minimum: 0.3 // 初始化时的最小百分比
})


//全局前置路由守卫
router.beforeEach((to,from,next) => {
  // 每次切换页面时，调用进度条
  NProgress.start();
  if(to.path.startsWith("/admin")){
    if(window.sessionStorage.getItem("user")){
      next()
    }else{
      next({path:'/login'})
    }
  }else{
    next();//!!这里一定要写else   因为next和return不一样，会继续执行
  }

})

router.afterEach(() => {
  // 在即将进入新的页面组件前，关闭掉进度条
  NProgress.done()
})

Vue.use(ElementUI);
Vue.config.productionTip = false;
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");
